package java_thinking.unit_19._19_7_9;

import java_thinking.unit_19._19_1_6.Enums;

/**
 * @Desc:   19.7.2 如果要与一大堆类型打交道时，接口就不如enum好用了，例如创建一个枚举的枚举
 * @author: cww
 * @DateTime: 2019-05-22 23:43
 */

public enum  Course {
    APPETIZER(Food.Appetizer.class),
    MAINCOURSE(Food.MainCourse.class),
    DESSERT(Food.Dessert.class),
    COFFEE(Food.Coffee.class);
    private Food[] values;
    private Course(Class<? extends Food> kind) {
        values = kind.getEnumConstants();
    }
    public Food randomSelection() {
        return Enums.random(values);
    }
}

class Meal {
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            //遍历每一个Course实例来获得枚举的枚举的值
            for (Course course : Course.values()) {
                Food food = course.randomSelection();
                System.out.println(food);
            }
            System.out.println("--------");
        }
    }
}
